-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add mongodb-ts-autocomplete package MONGOSH-2034 #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
24c2ad2
to
8b624a4
Compare
185e497
to
6d9a9d7
Compare
import path from 'path'; | ||
|
||
function replaceImports(code: string) { | ||
// This just makes it possible to work on mql.ts because then the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually my stubbed mql.ts file doesn't even use the bson library at the moment, but this will become relevant again once we have the real mql.ts or otherwise use something that depends on loading in the bson library.
// TODO: We need MONGOSH-2170 so that we can use the generated MQL types via | ||
// the Shell API to autocomplete fields in | ||
// ServerSchema[databaseName][collectionName].schema | ||
it.skip('completes a collection field name in a query', async function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ Just FYI.
packages/mongodb-ts-autocomplete/src/fixtures/autocomplete-types.ts
Outdated
Show resolved
Hide resolved
'fixtures', | ||
'autocomplete-types.ts', | ||
); | ||
await fs.writeFile(filepath, code, 'utf-8'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. So the problem with doing it this way is that the shell api is now included in the bundle twice. Once in the api export which contains a giant api
string and then again on this side where we generate a file to be included.
But I do kinda want to post-process the api here to change imports so unless we do the replaceImports() thing inside shell-api already there's probably no easy way around it.
Until we do the same thing for mql as we do for shell-api we kinda have to read the file as a string on this side and include the result in the bundle anyway so that we can pass that to the language service.
And for bson where we need the library as a string we have to read it at compile time and generate a string to be included in the bundle that can be passed to the language service regardless, because we're probably not going to be modifying the bson library to add that export.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK what I do now is I don't include the shell api inside autocomplete-types.ts. Once we have a real mql.ts we'll do the same for it. MongoDBAutocompleter just adds in the shell api next to autocompleteTypes itself. That way we don't have this in the bundle twice.
So autocomplete-types.ts is only for modules that don't export a a giant string.
Currently still works with fake mql types, but the shell-api ones are at least the real ones.
TODO: separate tickets